package com.example.text2.adapter;

import android.content.Context;
import android.media.Image;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.text2.R;
import com.example.text2.bean.Bean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 段傅华 on 2018/12/13.
 */

public class RlvAdapter extends RecyclerView.Adapter {
    private  Context mContext;
    private  ArrayList<Bean.ResultsBean> mList;

    public RlvAdapter(ArrayList<Bean.ResultsBean> list, Context context) {
        this.mList=list;
        this.mContext=context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(parent.getContext()).inflate(R.layout.itemlayout, null, false);
        MyViewHolder myViewHolder = new MyViewHolder(inflate);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
        MyViewHolder holder1= (MyViewHolder) holder;
        Glide.with(mContext).load(mList.get(position).getUrl()).placeholder(R.mipmap.ic_launcher).into(holder1.mIv);
    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public void addData(List<Bean.ResultsBean> list) {
        mList.addAll(list);
        notifyDataSetChanged();
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        final ImageView mIv;

        public MyViewHolder(View itemView) {
            super(itemView);
            mIv = itemView.findViewById(R.id.item_iv);
        }
    }
}
